<template>
	<view class="content">
		<image class="logo" src="/static/img/jslog.jpg"></image>
		<view class="text-area">
			<form>
			<input type='text' class="inputText" v-model="account" placeholder="请输入帐号" >
			<input type='password' class="inputText" v-model="passwd" placeholder="请输入密码" >
			<button class="btn" @click="login()" >登 录</button>
			</form>
		</view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				account:'',
				passwd:'',
			}
		},
		onLoad() {

		},
		methods: {
			login(){
				let that = this
				if (!this.account|| this.account == null || this.account==undefined || this.account=='undefined') {
					alert('账号 不能为空');
					return
				}
				
				if (!this.passwd|| this.passwd == null || this.passwd==undefined || this.passwd=='undefined') {
					alert('密码 不能为空');
					return
				}
				uni.request({
				    url: that.$host+'/api/v1/login/login', // 你的API接口地址
				    method: 'POST',
					header:{'content-type':'application/x-www-form-urlencoded;charset=utf-8',},
				    data: {
						phone:this.account,
						passwd:this.passwd,
						},
				    success: (res) => {
						if(res.data.code == 200){
							let userlogin = JSON.stringify({id:res.data.data.Id,nickname:res.data.data.Nickname,token:res.data.data.Token,identify_comm:res.data.data.Identify_comm, avatar:res.data.data.Avatar,phone:res.data.data.Phone})
							uni.removeStorage({
								key: 'jsloguser',
								success: function (res) {
									console.log('success');
								}
							});
							try {
								uni.setStorageSync('jsloguser', userlogin);
								uni.switchTab({
								    url: '/pages/index/index'
								});
							} catch (e) {
								console.error('用户数据保存失败');
							}
						}else{
							alert(res.data.msg)
						}
				    },
				    fail: (err) => {
						alert(err)
				    }
				});
			},
		}
	}
</script>

<style>

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

.inputText{
    min-height: 76rpx;
    border: 1rpx solid #dadbde;
    font-size: 36rpx;
    padding-left: 20rpx;
    border-radius: 8rpx;
    margin-left: 25rpx;
    margin-top: 20rpx;
	width:90%;
	height:76rpx;
}
.btn {
    margin-top: 20rpx;
	width:60%;
	height:69rpx;
	line-height:69rpx;
	justify-content: center;
	background: #3E7BFA;
}
</style>
